﻿<#
    对pos 文件做处理
#>


$file_path = "D:\360MoveData\Users\THINKBOOK\Desktop\BJPG_580007C8_pos_09281340.txt"

# 处理掉第一行,获取表头
$headers_array = $(Get-Content $file_path | select -Skip 1 -First 1) -split " " | foreach {if(-not $_ -eq ""){$_}}

# Write-Output $headers_array
echo "头个数 $($headers_array.Count)"
$headers_line = $headers_array -join ","

#Write-Output $headers_line

# $all_content = Import-Csv -Delimiter " " -Path $file_path
# Write-Output $all_content


<#
$(Get-Content $file_path | select -Skip 2 -First 1) | foreach -Process {
    $array = $_ -split " " | foreach {if(-not $_ -eq ""){$_}}
    echo "列个数 $($array.Count)"

}
#>

$new_path_array = $($file_path -split "\\")
$new_path = $new_path_array[0..$($new_path_array.count - 2)] -join "\"
$new_path = $new_path + "\" + "temp.txt"
echo $new_path

if (-not $(Test-Path $new_path)) {
    New-Item $new_path
}
else {
    echo "文件路径已存在"
}

$(Get-Content $file_path | select -Skip 1) > $new_path

echo $(Import-Csv $new_path -Delimiter " " -Verbose "" | select -First 2)







$data = New-Object System.Collections.ArrayList
$(Get-Content $file_path | select -Skip 1) | foreach {
    if (-not $_.ToString().Contains("(x/y/z-ecef=WGS84") ) {
        if ($_.ToString().StartsWith("%")) {
            $headers = $_ -split " " | foreach {
                if (-not $_ -eq "") {
                    $_
                }
            }
            #echo $headers
        }
        else {
            $line_data =  $_ -split " " | foreach {
                if (-not $_ -eq "") {
                    $_
                }
            }
            $data.Add([System.Collections.ArrayList]$line_data)
        }
    }
}
Write-Output $data[0]